package com.obook.epdhelper;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.Surface;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class EPDHelper {

    private static EPDHelper instance = null;
    //private final static long HWC_EINK_HANDWRITTEN = 0x40000;
    public enum Mode {
        DU(0x02),
        GC16(0x4),
        GC16_LOCAL(0x84),
        DU_RECT(0x402),
        GC16_RECT(0x404),
        A2_RECT(0x410),
        GC16_LOCAL_RECT(0x484),
        GL16(0x20), //常用于白底黑字刷新场景，如阅读场景
        AUTO(0x8000); //自动模式，由驱动决定刷新模式，会暂用较大带宽
        private int val;
        Mode(int m) {
            val = m;
        }

        public int value() {
            return val;
        }
    }

    static public EPDHelper getInstance() {
        if (instance == null)
            instance = new EPDHelper();;
        return instance;
    }

    private EPDHelper() {
    }

    public void setRefreshMode(Window window, Mode m) {
        System.out.println("mode" + m);
        window.setRefreshMode(m.value());
    }

    public void setSurfaceViewRefreshMode(SurfaceView surfaceview, Mode m) {
        System.out.println("SurfaceView mode" + m);
        //surfaceview.setRefreshMode(m.value()|WindowManager.LayoutParams.HWC_EINK_HANDWRITTEN);
        surfaceview.setRefreshMode(m.value());
    }

    /**
     * 使用GC16进行整屏刷新
     *
     * @param window 需要刷新的窗口
     * @param rightNow true表示立即进行一次整屏刷新，false表示将在下一帧进行整屏刷新。
     */
    public void forceGLobalRefresh(Window window, boolean rightNow){
        System.out.println("forceGlobalRefresh:" + rightNow);
        window.forceGlobalRefresh(rightNow);
    }

    /**
     * 限制Gu16连续刷新次数
     *
     * @param count count=0表示不做限制；count=1表示每次GC16刷新；2<=count<=20表示连续count次GU16刷新后下一帧进行GC16整屏刷新。
     */
    public void setGu16RefreshLimit(Window window, int count){
        System.out.println("setGu16RefreshLimit:" + count);
        window.setGu16RefreshLimit(count);
    }
}
